 

/**
 * 判断token是否可用
 */
module.exports = function () {
  return async function (ctx, next) {
    try {
      const token1 = ctx.header.authorization  // 获取jwt
      var arr = null
      var token = null
      if(token1){
        arr = token1.split(' ')
        token = ctx.request.body.token ? ctx.request.body.token : arr[1]
      }else{
        arr = [],
        token = null
      } 
      await next()
    } catch (err) {

      console.log('解析后的err: --------------')
      if (err.status === 401) {
        ctx.body = {
          code: -200,
          message: '认证失败'
        }
      } else {
        err.status = 404
        ctx.body = '404'
        console.log('不服就是怼：' ,err)
      }
    }
  }
}